package com.airforce.mappers;

import com.airforce.model.wechat_user;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface wechat_userMapper {
    @Delete({
        "delete from wechat_user",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into wechat_user (id, name, ",
        "openid, zone, lotterynum, ",
        "avatarURL, createtime, ",
        "updatetime, share, ",
        "sharenum, servicesname)",
        "values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, ",
        "#{openid,jdbcType=VARCHAR}, #{zone,jdbcType=VARCHAR}, #{lotterynum,jdbcType=INTEGER}, ",
        "#{avatarurl,jdbcType=VARCHAR}, #{createtime,jdbcType=TIMESTAMP}, ",
        "#{updatetime,jdbcType=TIMESTAMP}, #{share,jdbcType=TINYINT}, ",
        "#{sharenum,jdbcType=INTEGER}, #{servicesname,jdbcType=VARCHAR})"
    })
    int insert(wechat_user record);

    @InsertProvider(type=wechat_userSqlProvider.class, method="insertSelective")
    int insertSelective(wechat_user record);

    @Select({
        "select",
        "id, name, openid, zone, lotterynum, avatarURL, createtime, updatetime, share, ",
        "sharenum, servicesname",
        "from wechat_user",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="openid", property="openid", jdbcType=JdbcType.VARCHAR),
        @Result(column="zone", property="zone", jdbcType=JdbcType.VARCHAR),
        @Result(column="lotterynum", property="lotterynum", jdbcType=JdbcType.INTEGER),
        @Result(column="avatarURL", property="avatarurl", jdbcType=JdbcType.VARCHAR),
        @Result(column="createtime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="updatetime", property="updatetime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="share", property="share", jdbcType=JdbcType.TINYINT),
        @Result(column="sharenum", property="sharenum", jdbcType=JdbcType.INTEGER),
        @Result(column="servicesname", property="servicesname", jdbcType=JdbcType.VARCHAR)
    })
    wechat_user selectByPrimaryKey(Integer id);

    @UpdateProvider(type=wechat_userSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(wechat_user record);

  @UpdateProvider(type = wechat_userSqlProvider.class,method = "updateBysharmadd")
  int updateBysharmadd(wechat_user record);

    @Update({
        "update wechat_user",
        "set name = #{name,jdbcType=VARCHAR},",
          "openid = #{openid,jdbcType=VARCHAR},",
          "zone = #{zone,jdbcType=VARCHAR},",
          "lotterynum = #{lotterynum,jdbcType=INTEGER},",
          "avatarURL = #{avatarurl,jdbcType=VARCHAR},",
          "createtime = #{createtime,jdbcType=TIMESTAMP},",
          "updatetime = #{updatetime,jdbcType=TIMESTAMP},",
          "share = #{share,jdbcType=TINYINT},",
          "sharenum = #{sharenum,jdbcType=INTEGER},",
          "servicesname = #{servicesname,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(wechat_user record);
    @Select("select * from wechat_user ORDER BY id desc")
    List<wechat_user> selectByall();

    @Select("select * from wechat_user where name=#{name}")
    List<wechat_user> selectBylist(String name);

    @Select("select * from wechat_user where id=#{id}")
    wechat_user selectByIdAndName(@Param("id") Integer id);

    @Select("select id,name,lotterynum,avatarURL,share,sharenum,servicesname from wechat_user where openid=#{opneid}")
    wechat_user selectByopenid(String openid);

    @Update("update  wechat_user set sharenum=sharenum+1  where openid=#{openid}")
    int updataBynumadd(String  openid);

    @Update("update  wechat_user set lotterynum=lotterynum-1  where openid=#{openid}")
    int updataBynumreduce(String openid);
    @Select("select COUNT(*) from wechat_user")
    int countmax();



}